//
//  MDUtil.m
//  EpointMobileOA
//
//  Created by MagicStudio on 12-4-18.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MDUtil.h"
#import <CommonCrypto/CommonDigest.h>

@implementation MDUtil

+ (NSString*) authPassword:(NSString *)oldPassword
{
    NSString *password = [oldPassword copy];
    if (password == nil || [password length] == 0)
    {
        return password;
    }
    const char *cstr = [password cStringUsingEncoding:NSUTF8StringEncoding];
    NSData *data = [NSData dataWithBytes:cstr length:password.length];
    
    uint8_t digest[CC_SHA1_DIGEST_LENGTH];
    
    CC_SHA1(data.bytes, data.length, digest);
    
    NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
    
    for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
        [output appendFormat:@"%02x", digest[i]];
    
    return [output uppercaseString]; 
}

@end
